<?php

/**
 * @file Menu
 * @author garypradoruiz <garypradoruiz@gmail.com>
 * @link mailto:garypradoruiz@gmail.com
 * @copyleft 2012 garypradoruiz
 * @license GPL
 * @version 1
 */
class Admin_View_Helper_Menu extends Zend_Controller_Action_Helper_Abstract {

    function Menu($baseurl) {
        $auth = Zend_Auth::getInstance();
        $idgroup = $auth->getIdentity()->idgroup;
        $m = new Admin_Model_DbTable_Resources();
        $name_group = new Groups_Model_DbTable_Groups();
        $name_group = $name_group->getName($idgroup);
        if ($name_group == 'superadmin') {
            $modules = $m->fetchAll();
        } else {
            $modules = $m->getModulesGroup($idgroup, 0);
        }
        $menu = '';
        $band_mod = '';
        foreach ($modules as $mod) {
            if ($band_mod != $mod['module']) {
                $menu .= "<h3>$mod[module]</h3>";
                $band_mod = $mod['module'];
            }
            $menu .= "<ul class='toggle'>
                         <li class='icn_security'><a href='$baseurl/$mod[module]/$mod[controller]/$mod[view]'>$mod[name]</a></li>
                      </ul>";
        }
        return $menu;
    }
    
}
?>
